<#include '/pages/taglib/core.ftl'>
<#include '/pages/taglib/common.ftl'>
<#include '/pages/taglib/container.ftl'>

<#assign tabId=fn.id>

<@script src="/static/espirit/scripts/espirit/eap/sa/template.js"/>
<script>
	when('eap_sa_template', function() {
		eap_sa_template.init('${tabId}');
	});

	function applyTemplate(isTemplate) {
		eap_sa_template.applyTemplate(isTemplate, '${tabId}', '<@i18n name="model.espirit.eap.sa.user.fieldPermission"/>');
	}
	function showFieldPrivilege(isModelPrivilege) {
		eap_sa_template.showFieldPrivilege(isModelPrivilege, '<@i18n name="model.espirit.eap.sa.user.fieldPermission"/>');
	}
</script>
<@form name='_templateForm' action='/espirit/eap/sa/template.update.html' from='/espirit/eap/sa/template._add.html' clazz='jform'>
	<@hidden name="model.id"/>
	
	<@container>
		<@text name="model.name" required=true label="名称"/>
		<@text name="model.description" label="描述"/>
	</@container>

	<div class="j-form-item">
		<label class="label">${action.getText('model.espirit.eap.sa.user.template')}:</label>
		<span class="span" style="width: 450px">
			<#assign initData = fn.service('generic').searchAll(fn.newModel('com.espirit.eap.sa.Template')).data>
			<#assign initData = fn.insert(initData, 0, fn.newModel('com.espirit.eap.sa.Template'))>
			<@select collection=initData width=158 name='model.userTemplate.id'/>
			<input type="button" class="button" style="float: none;" value="${action.getText('应用模板')}" onclick="applyTemplate(true)">
			<#if model?if_exists.id?? && model.userTemplatePrivileges?size gt 0>
				<a href="javascript:void(0)" onclick="showFieldPrivilege(true)"><@i18n name='model.espirit.eap.sa.user.modelFieldPermission'/></a>
				&nbsp;&nbsp;<a href="javascript:void(0)" onclick="showFieldPrivilege(false)"><@i18n name='model.espirit.eap.sa.user.fieldPermission'/></a>
			</#if>
		</span>
	</div>
	
	<#assign tmp = ps.addExtraName('privileges', '', '')>
	<div id="tplPrivilegeCtn" class="loading" style="min-height: 20px;clear:both"></div>
</@form>

<@container clazz="jcontainer jcontainer-buttonInput">
	<input type=button onclick="eap_sa_template.saveTempatePrivilege(this)" value="${action.getText('保存')}">
	<span style="width: 5px;float: left;">&nbsp;</span>
	<input type=button onclick="initPrivilege()" value="${action.getText('取消')}">
</@container>